package com.ruoyi.project.system.partymember.controller;

import java.util.List;

import com.ruoyi.project.system.partymember.service.IPartyRelationshipChangeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.partymember.domain.PartyRelationshipChange;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.text.Convert;

/**
 * 党员组织关系变动Controller
 * 
 * @author ruoyi
 * @date 2023-07-15
 */
@Controller
@RequestMapping("/system/partymember/change")
public class PartyRelationshipChangeController extends BaseController
{
    private String prefix = "system/partymember/change";

    @Autowired
    private IPartyRelationshipChangeService partyRelationshipChangeService;

    @RequiresPermissions("system:partymember:change:view")
    @GetMapping()
    public String change()
    {
        return prefix + "/change";
    }

    /**
     * 查询党员组织关系变动列表
     */
    @RequiresPermissions("system:partymember:change:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PartyRelationshipChange partyRelationshipChange)
    {
        startPage();
        List<PartyRelationshipChange> list = partyRelationshipChangeService.selectPartyRelationshipChangeList(partyRelationshipChange);
        return getDataTable(list);
    }

    /**
     * 导出党员组织关系变动列表
     */
    @RequiresPermissions("system:partymember:change:export")
    @Log(title = "党员组织关系变动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PartyRelationshipChange partyRelationshipChange)
    {
        List<PartyRelationshipChange> list = partyRelationshipChangeService.selectPartyRelationshipChangeList(partyRelationshipChange);
        ExcelUtil<PartyRelationshipChange> util = new ExcelUtil<PartyRelationshipChange>(PartyRelationshipChange.class);
        return util.exportExcel(list, "党员组织关系变动数据");
    }

    /**
     * 新增党员组织关系变动
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存党员组织关系变动
     */
    @RequiresPermissions("system:partymember:change:add")
    @Log(title = "党员组织关系变动", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PartyRelationshipChange partyRelationshipChange)
    {
        return toAjax(partyRelationshipChangeService.insertPartyRelationshipChange(partyRelationshipChange));
    }

    /**
     * 修改党员组织关系变动
     */
    @RequiresPermissions("system:partymember:change:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PartyRelationshipChange partyRelationshipChange = partyRelationshipChangeService.selectPartyRelationshipChangeById(id);
        mmap.put("partyRelationshipChange", partyRelationshipChange);
        return prefix + "/edit";
    }

    /**
     * 修改保存党员组织关系变动
     */
    @RequiresPermissions("system:partymember:change:edit")
    @Log(title = "党员组织关系变动", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PartyRelationshipChange partyRelationshipChange)
    {
        return toAjax(partyRelationshipChangeService.updatePartyRelationshipChange(partyRelationshipChange));
    }

    /**
     * 删除党员组织关系变动
     */
    @RequiresPermissions("system:partymember:change:remove")
    @Log(title = "党员组织关系变动", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(partyRelationshipChangeService.deletePartyRelationshipChangeByIds(Convert.toLongArray(ids)));
    }
}